package com.aube.interact.fighter.model;

import com.huyn.baseframework.model.BaseModel;
import com.huyn.baseframework.utils.StringUtils;

import java.util.List;

/**
 * Created by huyaonan on 15/11/7.
 */
public class OptionResultModel extends BaseModel {
    public List<OptionItem> data;

    public OptionResultModel(List<OptionItem> items) {
        data = items;
    }

    public int getCorrectAnswerCount(String id) {
        if(data == null || StringUtils.isBlank(id))
            return 0;
        for(OptionItem item : data) {
            if(id.equalsIgnoreCase(item.optionId))
                return item.count;
        }
        return 0;
    }

    public int getAnswerCount(String id) {
        if(data == null || StringUtils.isBlank(id))
            return 0;
        for(OptionItem item : data) {
            if(id.equalsIgnoreCase(item.optionId))
                return  item.count;
        }
        return 0;
    }

    public int[] getAnswerResult(String id) {
        int[] result = {0,0};
        if(data == null || StringUtils.isBlank(id))
            return result;
        int total=0, selected=0;
        for(OptionItem item : data) {
            if(id.equalsIgnoreCase(item.optionId))
                selected = item.count;
            total+=item.count;
        }
        if(total == 0)
            return result;
        result[0] = total;
        result[1] = selected*100/total;
        return result;
    }

    public OptionItem getItem(int index) {
        return data.get(index);
    }

}
